<?php

class AppContent {

      public function showHtml(){
          //recuperar node pelo id com nodeDAO
       echo
        '
          <div class="content">

            <div class="content_box">'.$this->showTaxo().

         ' </div>

            <!--<div class="content_box last_box">
            	<h2>Web Projects</h2>

                <div class="gallery">
		    <a href="images/gallery/image_01_b.jpg" class="pirobox" title="Project 1"><img src="images/gallery/image_01.jpg" alt="1" /></a>
                    <a href="images/gallery/image_02_b.jpg" class="pirobox" title="Project 2"><img src="images/gallery/image_02.jpg" alt="2" /></a>
                    <a href="images/gallery/image_03_b.jpg" class="pirobox" title="Project 3"><img src="images/gallery/image_03.jpg" alt="3" /></a>
                </div> 

              <div class="cleaner h20"></div>
              <a href="#"><strong>View All Projects</strong></a></div>-->

        </div>

        <div class="cleaner"></div>
    </div><!-- End of Content -->
        ';
    }

     public function showTaxo(){
        $nodeDao = new NodeDao();

        if(Config::$option != 0){
            return $this->showContent();
        }
        if(Config::$current==0){
            return;
        }

        require_once('DAO/mySqlConnect.php'); // create the mySqlConnect class
        $mySqlConnect = new MySqlConnect();
        $taxo = NodeDao::db_node_by_id($mySqlConnect->getLinkDB(), Config::$current);

        $string = '<table>';
                    

        $string = $string.'<tr>';
        $string = $string.'<td>';
        $string = $string.$taxo->taxo->nome;
        $string = $string.'</td>';
        $string = $string.'</tr>';

        $string = $string.'<tr>';
        $string = $string.'<td>';
        $string = $string.$taxo->taxo->descricao;
        $string = $string.'</td>';
        $string = $string.'</tr>';
            
        $string = $string.'</table>';

        $string = $string.'<br/>';

        EspecieDao::init();
        EspecieDao::getSonEspecies($mySqlConnect->getLinkDB(),$taxo->id);

        if(EspecieDao::$Arr->count()>0){
            $string = $string.'<h5>Listagem de Todas as Espécies</h5>';
        }



        $string = $string.'<form action="'.Config::$domainName.'/Application.php" method="GET">
            Qtde de Linhas:
            <SELECT name="qtdLinhas">
                <OPTION VALUE="1">01</OPTION>
		<OPTION VALUE="5">05</OPTION>
		<OPTION VALUE="10">10</OPTION>
		<OPTION VALUE="15">15</OPTION>
		<OPTION VALUE="20">20</OPTION>
            </SELECT>

            <input type="submit"/> <br /><br />
            </form>
        ';

        $string = $string.'<div class="tblDiv"><table align="center" border="1">';
           
       

          $iterator = EspecieDao::$Arr->getIterator();
        if (isset ($_GET['qtdLinhas'])){
            Config::$qtdeLinhas = $_GET['qtdLinhas'];
            
         }

         if(isset ($_GET['primeiraLinha'])){
             Config::$primeiraLinha = $_GET['primeiraLinha'];
         }
         if(isset ($_GET['ultimaLinha'])){
             Config::$ultimaLinha = $_GET['ultimaLinha'];
         }

         

         if (isset ($_GET['indexar'])){
            if ($_GET['indexar']==0) {
              if (Config::$primeiraLinha > 0){
                Config::$ultimaLinha = (Config::$ultimaLinha - Config::$qtdeLinhas);
                Config::$primeiraLinha = (Config::$primeiraLinha - Config::$qtdeLinhas);
              }
            }else{
              if(Config::$ultimaLinha < $iterator->count()){
                 Config::$primeiraLinha = (Config::$primeiraLinha + Config::$qtdeLinhas);
                 Config::$ultimaLinha = (Config::$ultimaLinha + Config::$qtdeLinhas);
              }
            }

        }


        

        $numLinhas = 0 ;
        while($iterator->valid()) {
            if (($numLinhas < Config::$qtdeLinhas)  ){
                Config::$ultimaLinha = (Config::$primeiraLinha + Config::$qtdeLinhas);
                if(($iterator->key() >= Config::$primeiraLinha) && ($iterator->key() <= Config::$ultimaLinha)){

                $current = $iterator->current();
                $string = $string.'<tr>';
                $string = $string.'<td>';
                $string = $string.$current->nome;
                $string = $string.'</td>';
                $string = $string.'</tr>';

                $numLinhas++;
                }
            }else{
                break;
            }

            
            $iterator->next();
               
           }
        $string = $string.'</table></div>';

      
        $string = $string.'
            <a href="'.Config::$domainName.'/Application.php?indexar=0&qtdLinhas='.Config::$qtdeLinhas.'&primeiraLinha='.Config::$primeiraLinha.'"><<< Anterior </a>
            <a href="'.Config::$domainName.'/Application.php?indexar=1&qtdLinhas='.Config::$qtdeLinhas.'&primeiraLinha='.Config::$primeiraLinha.'">Próximo >>> </a>
        ';

        $string = $string.'<h5>Esta classificação tem '.$this->showSon($taxo,$mySqlConnect->getLinkDB()).' filhos</h5>';

        $mySqlConnect->closeDB();
        return $string;

    }

     public function showSon($taxo,$mysql) {
        NodeDao::$son=0;
        NodeDao::$flag=false;
        NodeDao::getSonNumber($mysql, $taxo->id);
        return NodeDao::$son;
    }

    public function showContent(){
        if(Config::$option==1){
             $string =
                '
                <h2>Cadastrar Usuário</h2>

                <fieldset>
                    <legend><h5>Formulário de Cadastro</h5> </legend>


                <form action="./Application.php" method="POST">
                    <dl>
                        <dd>Nome:</dd>
                        <dt> <input type="text" name="nome"/></dt>
                    </dl>

                    <dl>
                        <dd>Login:</dd>
                        <dt> <input type="text" name="login"/></dt>
                    </dl>

                    <dl>
                        <dd>Senha:</dd>
                        <dt> <input type="password" name="senha"/></dt>
                    </dl> 

                    <dl>
                        <dd></dd>
                        <dt> <input type="submit" name="cadastrar"/></dt>
                    </dl>
                </form>

                </fieldset>
                ';
            return $string;
        }if(Config::$option==2){
            $string =
            '<center>
            	<h2>Autentique-se</h2>

                <div class="login_form">
                        <form method="post" action="Application.php">
                            <p><span>User Name:</span>
                            <input type="text" class="username" name="username" class="login_input" />
                            </p>
                            <p><span>Password:</span>
                            <input type="password" class="password" name="password" class="login_input" />
                            </p>
                            <input type="submit" name="submit" class="login_submit" value="" />
                        </form>
		</div>
           </center>';
            return $string;
        }
    }


}
?>
